<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="最低分位次预测" prop="lowestForecast">
        <el-input
          v-model="queryParams.lowestForecast"
          placeholder="请输入最低分位次预测"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业类型" prop="specialtyType">
        <el-input
          v-model="queryParams.specialtyType"
          placeholder="请输入专业类型"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预测年份" prop="forecastYear">
        <el-input
          v-model="queryParams.forecastYear"
          placeholder="请输入预测年份"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业名称" prop="specialtyName">
        <el-input
          v-model="queryParams.specialtyName"
          placeholder="请输入专业名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="省份" prop="provinceName">
<!--        <el-select v-model="queryParams.provinceName" placeholder="请选择省份" clearable size="small">
          <el-option label="请选择字典生成" value=""/>
        </el-select>-->
        <el-input
          v-model="queryParams.provinceName"
          placeholder="请输入省份"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="首选科目" prop="firstSubject">
        <el-input
          v-model="queryParams.firstSubject"
          placeholder="请输入首选科目"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学校" prop="schoolName">
        <el-input
          v-model="queryParams.schoolName"
          placeholder="请输入学校"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:CompassSimulateFill:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:CompassSimulateFill:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:CompassSimulateFill:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <importData
          v-hasPermi="['system:CompassSimulateFill:edit']"
          title="填报模拟"
          action="CompassSimulateFill"
        >
        </importData>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:CompassSimulateFill:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="CompassSimulateFillList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="省份" align="center" prop="provinceName"/>
      <el-table-column label="预测年份" align="center" prop="forecastYear"/>
      <el-table-column label="学校" align="center" prop="schoolName"/>
      <el-table-column label="专业类型" align="center" prop="specialtyType"/>
      <el-table-column label="专业名称" align="center" prop="specialtyName"/>
      <el-table-column label="首选科目" align="center" prop="firstSubject"/>
      <el-table-column label="最低分位次预测" align="center" prop="lowestForecast"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:CompassSimulateFill:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:CompassSimulateFill:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改模拟填报对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="750px" append-to-body>
      <el-form ref="form" :inline="true" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="省份" prop="provinceName" :rules="{required: true, message: '请输入省份'}">
          <!--<el-select v-model="form.provinceName" placeholder="请选择省份">
            <el-option label="请选择字典生成" value=""/>
          </el-select>-->
          <el-input v-model="form.provinceName" placeholder="请输入省份"/>
        </el-form-item>
        <el-form-item label="预测年份" prop="forecastYear" :rules="{required: true, message: '请输入预测年份'}">
          <el-input v-model="form.forecastYear" placeholder="请输入预测年份"/>
        </el-form-item>
        <el-form-item label="学校" prop="schoolName" :rules="{required: true, message: '请输入学校'}">
          <el-input v-model="form.schoolName" placeholder="请输入学校"/>
        </el-form-item>
        <el-form-item label="专业名称" prop="specialtyName" :rules="{required: true, message: '请输入专业名称'}">
          <el-input v-model="form.specialtyName" placeholder="请输入专业名称"/>
        </el-form-item>
        <el-form-item label="首选科目" prop="firstSubject" :rules="{required: true, message: '请输入首选科目'}">
          <el-input v-model="form.firstSubject" placeholder="请输入首选科目"/>
        </el-form-item>
        <el-form-item label="最低分位次预测" prop="lowestForecast" :rules="{required: true, message: '请输入最低分位次预测'}">
          <el-input v-model="form.lowestForecast" placeholder="请输入最低分位次预测"/>
        </el-form-item>
        <el-form-item label="10%风险" prop="percent10" :rules="{required: true, message: '请输入10%风险'}">
          <el-input v-model="form.percent10" placeholder="请输入10%风险"/>
        </el-form-item>
        <el-form-item label="省90%风险" prop="percent90" :rules="{required: true, message: '请输入90%风险'}">
          <el-input v-model="form.percent90" placeholder="请输入90%风险"/>
        </el-form-item>
        <el-form-item label="4年录取总人数" prop="totalEnrollment" :rules="{required: true, message: '请输入4年录取总人数'}">
          <el-input v-model="form.totalEnrollment" placeholder="4年录取总人数"/>
        </el-form-item>
        <el-form-item label="专业类型" prop="specialtyType" :rules="{required: true, message: '请输入专业类型'}">
          <el-input v-model="form.specialtyType" placeholder="请输入专业类型"/>
        </el-form-item>
        <el-divider content-position="left">往年分数，位次</el-divider>
        <el-col :span="8">
          <el-form-item label="年份一" prop="year1" label-width="85px">
            <el-input v-model="form.year1" placeholder="年份一" style="width: 140px"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="最低位次一" prop="lowestOrder1" label-width="85px">
            <el-input v-model="form.lowestOrder1" placeholder="最低位次一" style="width: 140px"/>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="最低分数一" prop="lowestScore1" label-width="85px">
            <el-input v-model="form.lowestScore1" placeholder="最低分数一" style="width: 140px"/>
          </el-form-item>
        </el-col>
        <el-form-item label="年份二" prop="year2" label-width="85px">
          <el-input v-model="form.year2" placeholder="年份二" style="width: 140px"/>
        </el-form-item>
        <el-form-item label="最低位次二" prop="lowestOrder2" label-width="85px">
          <el-input v-model="form.lowestOrder2" placeholder="最低位次二" style="width: 140px"/>
        </el-form-item>
        <el-form-item label="最低分数二" prop="lowestScore2" label-width="85px">
          <el-input v-model="form.lowestScore2" placeholder="最低分数二" style="width: 140px"/>
        </el-form-item>
        <el-form-item label="年份三" prop="year3" label-width="85px">
          <el-input v-model="form.year3" placeholder="年份三" style="width: 140px"/>
        </el-form-item>
        <el-form-item label="最低位次三" prop="lowestOrder3" label-width="85px">
          <el-input v-model="form.lowestOrder3" placeholder="最低位次三" style="width: 140px"/>
        </el-form-item>
        <el-form-item label="最低分数三" prop="lowestScore3" label-width="85px">
          <el-input v-model="form.lowestScore3" placeholder="最低分数三" style="width: 140px"/>
        </el-form-item>
        <el-form-item label="年份四" prop="year4" label-width="85px">
          <el-input v-model="form.year4" placeholder="年份四" style="width: 140px"/>
        </el-form-item>
        <el-form-item label="最低位次四" prop="lowestOrder4" label-width="85px">
          <el-input v-model="form.lowestOrder4" placeholder="最低位次四" style="width: 140px"/>
        </el-form-item>
        <el-form-item label="最低分数四" prop="lowestScore4" label-width="85px">
          <el-input v-model="form.lowestScore4" placeholder="最低分数四" style="width: 140px"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listCompassSimulateFill,
  getCompassSimulateFill,
  delCompassSimulateFill,
  addCompassSimulateFill,
  updateCompassSimulateFill,
  exportCompassSimulateFill
} from "@/api/system/CompassSimulateFill";
import dictMixins from "@/views/mixins/dictMixins";

export default {
  mixins: [dictMixins],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 模拟填报表格数据
      CompassSimulateFillList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        lowestForecast: null,
        specialtyType: null,
        forecastYear: null,
        specialtyName: null,
        provinceName: null,
        firstSubject: null,
        schoolName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询模拟填报列表 */
    getList() {
      this.loading = true;
      listCompassSimulateFill(this.queryParams).then(response => {
        this.CompassSimulateFillList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        lowestOrder1: null,
        percent10: null,
        totalEnrollment: null,
        year4: null,
        year3: null,
        year2: null,
        year1: null,
        lowestForecast: null,
        lowestScore4: null,
        lowestScore3: null,
        lowestScore2: null,
        lowestScore1: null,
        percent90: null,
        lowestOrder4: null,
        lowestOrder3: null,
        lowestOrder2: null,
        specialtyType: null,
        forecastYear: null,
        specialtyName: null,
        provinceName: null,
        firstSubject: null,
        schoolName: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加模拟填报";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCompassSimulateFill(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改模拟填报";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCompassSimulateFill(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addCompassSimulateFill(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除模拟填报编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delCompassSimulateFill(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(function () {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有模拟填报数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return exportCompassSimulateFill(queryParams);
      }).then(response => {
        this.download(response.msg);
      }).catch(function () {
      });
    }
  }
};
</script>
